<?php
require_once( dirname(dirname(__FILE__)) . '/thirdpart/qzone/config.php' );
include_once( dirname(dirname(__FILE__)) . '/thirdpart/qzone/txwboauth.php' );

$c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret']  );
$aa=$c->pub_abc($_SESSION['last_key']['openid']);
//print_r($aa);
$id = $_SESSION['last_key']['openid'];
$name = $aa['nickname'];

if(!$id) {
	need_login();
}

$sns = 'qzone:'.$id;
$exist_user = Table::Fetch('user', $sns, 'sns');
if ( $exist_user ) {
	Session::Set('user_id', $exist_user['id']);
	Utility::Redirect(get_loginpage(WEB_ROOT . '/index.php'));
}

include template('account_qzone');